// instanceof 就是判断构造函数的 prototype 属性是否出现在实例的原型链上。
function Animal (type) {
  this.type = type
}
function Dog (type) {
  Animal.call(this, type)
}
function Miao (tyep) {
  this.type = tyep
}
Dog.prototype = Object.create(Animal.prototype)
Dog.prototype.constructor = Dog
let dog = mockNew(Dog, 'dog')
let miao = new Miao('你好')
console.log(myInstanceof(dog, Dog));
console.log(myInstanceof(miao, Dog));
function mockNew () {
  const constructor = [].shift.call(arguments)
  let obj = {}
  obj.__proto__ = constructor.prototype
  let ret = constructor.apply(obj, arguments)
  return ret instanceof Object ? ret : obj
}
function myInstanceof (left, right) {
  let proto = left.__proto__
  while (true) {
    if (proto === null) return false
    if (proto === right.prototype) return true
    proto = proto.__proto__
  }
}
// function myInstanceof1(left,right){
//   let proto = left.__proto__
//   while(true){
//     if(proto === null) return false
//     if(proto === right.prototype){
//       return true
//     }
//     proto = proto.__proto__
//   }
// }
